package main

import (
	"fmt"
)

func main() {
	/*
		s := []string{"red", "", "black", "", "", "pink", "blue", "yellow", "yellow"}
		slice := noSame(s)
		fmt.Println(slice)
	*/
	/*
		data := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
		s1 := data[8:]
		s2 := data[:5]
		copy(s2, s1)
		fmt.Println(s1, s2)
	*/
	sliceTest()

}

//字符串切片去空串
func noEmpty(slice []string) []string {
	s2 := make([]string, 0, 0)
	for _, str := range slice {
		if str != "" {
			s2 = append(s2, str)
		}
	}
	return s2
}
func sliceTest() {
	arr := [1024]string{"1", "2", "34", "56", "78", "910"}
	slice := arr[0:]
	s := slice
	fmt.Println("cap=", cap(s), "len=", len(s))
	slice[cap(slice)-1] = "4"
	slice[cap(slice)] = "4"
	fmt.Println("cap=", cap(s), "len=", len(s))
}

//操作源串
func noEmpty2(slice []string) []string {
	i := 0
	for _, s := range slice {
		if s != "" {
			slice[i] = s
			i++
		}
	}
	return slice[:i]
}

//字符串数组去重
func noSame(slice []string) []string {
	s := slice[:1]
	for _, s2 := range slice {
		for index, s3 := range s {
			if s3 == s2 {
				continue
			}
			if index == len(s)-1 {
				s = append(s, s2)
			}
		}
	}
	return s
}

func test01() {
	data := []int{5, 6, 7, 8, 9}
	afterdata := remove(data, 2)
	fmt.Println(afterdata)
}
func remove(data []int, index int) []int {
	copy(data[index:], data[index+1:])
	return data[:len(data)-1]
}
